<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Neon Admin Panel">
	<meta name="author" content="">
	
	<title>Green Soil | Register</title>
	

	<link rel="stylesheet" href="static/css/jquery-ui-1.10.3.custom.min.css">
	<link rel="stylesheet" href="static/css/entypo.css">
	<link rel="stylesheet" href="static/css/css.css">
	<link rel="stylesheet" href="static/css/bootstrap.css">
	<link rel="stylesheet" href="static/css/neon-core.css">
	<link rel="stylesheet" href="static/css/neon-theme.css">
	<link rel="stylesheet" href="static/css/neon-forms.css">
	<link rel="stylesheet" href="static/css/custom.css">

	<script src="static/js/jquery-1.11.0.min.js"></script>

	<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	
	
</head>
<body class="page-body login-page login-form-fall" data-url="http://neon.dev">


<!-- This is needed when you send requests via Ajax --><script type="text/javascript">
var baseurl = 'http://127.0.0.1:8080/user/login';
</script>
	
<div class="login-container">
	
	<div class="login-header login-caret">
		
		<div class="login-content">
			
			<a href="index.html" class="logo">
				<img src="static/picture/green.png" width="280" alt="">
			</a>
			
			<p class="description">创建一个新账户，需要花费一点点时间</p>
			
			<!-- progress bar indicator -->
			<div class="login-progressbar-indicator">
				<h3>43%</h3>
				<span>logging in...</span>
			</div>
		</div>
		
	</div>
	
	<div class="login-progressbar">
		<div></div>
	</div>
	
	<div class="login-form">
		
		<div class="login-content">
			
			<form method="post" role="form" id="form_register">
				
				<div class="form-register-success">
					<i class="entypo-check"></i>
					<h3>You have been successfully registered.</h3>
					<p>We have emailed you the confirmation link for your account.</p>
				</div>
				
				<div class="form-steps">
					
					<div class="step current" id="step-1">
					
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-user"></i>
								</div>
								
								<input type="text" class="form-control" name="name" id="name" placeholder="所属单位(2-10个字符)" autocomplete="off">
							</div>
						</div>
						
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-phone"></i>
								</div>
								<input type="text" class="form-control" name="phone" id="phone" placeholder="手机号码(11位数字)" autocomplete="off">
							</div>
						</div>
						
						
						<div class="form-group">
							<button type="button" data-step="step-2" class="btn btn-primary btn-block btn-login">
								<i class="entypo-right-open-mini"></i>
								Next Step
							</button>
						</div>
						
						<div class="form-group">
							Step 1 of 2
						</div>
					
					</div>
					
					<div class="step" id="step-2">
					
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-user-add"></i>
								</div>
								
								<input type="text" class="form-control" name="username" id="username" placeholder="昵称(2-10个字符)"  autocomplete="off">
							</div>
						</div>
					
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-mail"></i>
								</div>
								
								<input type="text" class="form-control" name="email" id="email"  placeholder="邮箱" autocomplete="off">
							</div>
						</div>
						
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-lock"></i>
								</div>
								
								<input type="password" class="form-control" name="password" id="password" placeholder="密码(2-10个字符)" autocomplete="off">
							</div>
						</div>
						
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<i class="entypo-lock"></i>
								</div>
								
								<input type="password" class="form-control" name="old" id="old" placeholder="确认密码" autocomplete="off">
							</div>
						</div>
						
						<div class="form-group">
							<button type="submit" id='my' class="btn btn-success btn-block btn-login">
								<i class="entypo-right-open-mini"></i>
								Complete Registration
							</button>
						</div>
						
						<div class="form-group">
							Step 2 of 2
						</div>
						
					</div>
					
				</div>
				
			</form>
			
			
			<div class="login-bottom-links">
				
				<a href="login.html" class="link">
					<i class="entypo-lock"></i>
					Return to Login Page
				</a>
				
				<br>
				
				<a href="#">ToS</a>  - <a href="#">Privacy Policy</a>
				
			</div>
			
		</div>
		
	</div>
	
</div>


	<!-- Bottom Scripts -->
	<script src="static/js/main-gsap.js"></script>
	<script src="static/js/jquery-ui-1.10.3.minimal.min.js"></script>
	<script src="static/js/bootstrap.js"></script>
	<script src="static/js/joinable.js"></script>
	<script src="static/js/resizeable.js"></script>
	<script src="static/js/neon-api.js"></script>
	<script src="static/js/jquery.validate.min.js"></script>
	<script src="static/js/neon-register.js"></script>
	<script src="static/js/jquery.inputmask.bundle.min.js"></script>
	<script src="static/js/neon-custom.js"></script>
	<script src="static/js/neon-demo.js"></script>
	<script src="https://cdn.bootcss.com/crypto-js/3.1.9-1/crypto-js.min.js"></script>
	<script src="./gethost.js" type="text/javascript"></script>
	<script >
		
		function encryptByDES(message, key){
    		var keyHex = CryptoJS.enc.Utf8.parse(key);
    		var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
        		mode: CryptoJS.mode.ECB,
        		padding: CryptoJS.pad.Pkcs7
    		});
    		return encrypted.ciphertext.toString();
		}
		
		$("#my").on("click",function(){
			var name = $("#name").val();
			var phone = $("#phone").val();
			var username = $("#username").val();
			var email = $("#email").val();
			var password = $("#password").val();
			var old = $("#old").val();
			function isRealNum(val){
				if(val === "" || val ==null){
					return true;
				}else{
					return isNaN(val);
				}
			}

			function isNoBlank(val) {
				if(val === "" || val ==null){
					return true;
				}else{
					return false;
				}
			}

			if(isNoBlank(name)){
				alert("单位不能为空");
				return false;
			}
			if(isNoBlank(username)){
				alert("用户名不能为空");
				return false;
			}
			if(isNoBlank(email)){
				alert("邮箱不能为空");
				return false;
			}
			if(isNoBlank(password)){
				alert("密码不能为空");
				return false;
			}
			if(isNoBlank(old)){
				alert("请再次输入密码！");
				return false;
			}
			if(isRealNum(phone)){
				alert("手机号不能为空！且必须是数字");
				return false;
			}
			if(password!=old){
				alert("两次密码应保持一致");
				return false;
			}

			if(name.length>20){
				alert("单位信息太长！");
				return false;
			}

			if(phone.length!=11){
				alert("请输入11位手机号码")
				return false;
			}
			if(email.length>30){
				alert("邮箱太长！")
				return false;
			}

			if(username.length<=1){
				alert("昵称太短！")
				return false;
			}
			if(username.length>=10){
				alert("昵称太长！")
				return false;
			}


			if(password.length<=5){
				alert("密码太短！")
				return false;
			}

			if(password.length>20){
				alert("密码太长！")
				return false;
			}

			password=encryptByDES(password, "key");

			$.ajax({
				type:"POST",
				contentType:"application/x-www-form-urlencoded",
				url:"http://"+g_host+"/user/register",
				data:{
					"name":name,
					"telphone":phone,
					"username":username,
					"email":email,
					"password":password
				},
				xhrFields:{withCredentials:true},
				success:function(data){
					if(data.status == "success"){
						alert("注册成功!")
						window.location.href="login.html";
					}else{
						alert("注册失败，原因为"+data.data.errMsg);
					}
				},
				error:function(data){
					window.location.href="500.html";
				}
			});
			return false;
		});
		
	</script>
	

</body>
</html>